<?php
Globals::requireClass('Controller');
Globals::requireModel('User');
Globals::requireTable('User');
Globals::requireTable('Trysee');
Globals::requireTable('Tryseeorder');

class TryseeshareController extends Controller
{
    protected $UserTable;
    protected $TryseeTable;
    protected $TryseeOrderTable;
	
	public static $defaultConfig = array(
		'viewEnabled'	=> true,
		'layoutEnabled'	=> true,
		'title'			=> null
	);
	
	public function __construct($config = null)
	{
		parent::__construct($config);
		$this->UserTable = new UserTable($config);
		$this->TryseeTable = new TryseeTable($config);
		$this->TryseeOrderTable = new TryseeorderTable($config);
		dolog(json_encode($_GET));
	}
	
	public function indexAction()
	{
		$this->layout->pageTitle	= "test";
	}
	
	
	//分享试看视频（四期）
	public function tryseeshareurlAction(){
	    $uid = $this->getParam('uid');
	    $token = $this->getParam('token');
	    $machine_type = $this->getParam('machine_type');
	    $usermodel = new UserModel($this->config);
	    $uid = $usermodel->getUserBase($uid, $token ,$machine_type);
	    if($uid < 1){
	        echo json_encode(array('returncode'=>'-1','url'=>''));
	        exit();
	    }
	    
	    $id = $this->getIntParam('id');
	    $url = $this->getParam('url');
	    $shareuid = $this->getIntParam('shareuid');
	    
	    $date = date('Y-m-d H:i:s');
	    
	    $trysee = $this->TryseeTable->getRow($id);
	    $order_data = $this->TryseeOrderTable->getRow(array('status'=>2,'uid'=>$shareuid,'trysee_id'=>$id));
	    if((int)$trysee['id'] < 1 || (int)$order_data['id'] < 1){
	        echo json_encode(array('returncode'=>'-2','url'=>''));
	        exit();
	    }
	    
	    $newurl = $trysee['plus_url'].$url;
	    
	    echo json_encode(array('returncode'=>'0','url'=>$newurl));
	    exit();
	}
	
	protected function out()
	{
		$this->layout->nav		= 'index';
		parent::out();
	}
}

Config::extend('TryseeshareController', 'Controller');
